import Vue from 'vue';
import Router from 'vue-router';

/* Layout */
import Layout from '@/layout';

Vue.use(Router);

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index'),
      },
    ],
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/sso',
    component: () => import('@/views/login/sso'),
    hidden: true,
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true,
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true,
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    hidden: true,
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true },
      },
    ],
  },
  /* --------------------内容管理---------------------*/
  {
    path: '/content',
    component: Layout,
    redirect: '/content/index',
    name: 'content',
    meta: { title: '内容管理', icon: '' },
    children: [
      {
        path: '/content/index',
        name: 'index',
        component: () => import('@/views/content/index/index'),
        meta: { title: '内容管理', icon: '' },
      },
      {
        path: '/examine/index',
        name: 'examine',
        component: () => import('@/views/content/examine/index'),
        meta: { title: '审核管理', icon: '' },
      },
    ],
  },
  /* --------------------自动回复---------------------*/
  {
    path: '/autoReply',
    component: Layout,
    redirect: '/autoReply/index',
    name: 'autoReply',
    meta: { title: '自动回复', icon: '' },
    children: [
      {
        path: '/autoReply/index',
        name: 'autoReplyIndex',
        component: () => import('@/views/autoReply/index'),
        meta: { title: '自动回复', icon: '' },
      },
    ],
  },
  // 用户管理
  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    name: 'user',
    meta: { title: '用户管理', icon: '' },
    children: [
      {
        path: '/user/index',
        name: 'user',
        component: () => import('@/views/user/index'),
        meta: { title: '用户管理', icon: '' },
      },
    ],
  },
  // 订单管理
  {
    path: '/order',
    component: Layout,
    redirect: '/order/index',
    name: 'order',
    meta: { title: '订单管理', icon: '' },
    children: [
      {
        path: '/order/index',
        name: 'order',
        component: () => import('@/views/order/index'),
        meta: { title: '支付订单', icon: '' },
      },
      {
        path: '/order/refund',
        name: 'order',
        component: () => import('@/views/order/refund.vue'),
        meta: { title: '退款订单', icon: '' },
      },
    ],
  },
  // 订单管理
  {
    path: '/miniApp',
    component: Layout,
    redirect: '/miniApp/index',
    name: 'miniApp',
    meta: { title: '小程序管理', icon: '' },
    children: [
      {
        path: '/miniApp/index',
        name: 'miniApp',
        component: () => import('@/views/miniApp/index'),
        meta: { title: '小程序管理', icon: '' },
      },
    ],
  },
  // 充值档位管理
  {
    path: '/recharge',
    component: Layout,
    redirect: '/recharge/index',
    name: 'recharge',
    meta: { title: '充值档位管理', icon: '' },
    children: [
      {
        path: '/recharge/index',
        name: 'recharge',
        component: () => import('@/views/recharge/index'),
        meta: { title: '充值档位管理', icon: '' },
      },
    ],
  },
  // 商户号管理
  {
    path: '/merchant',
    component: Layout,
    redirect: '/merchant/index',
    name: 'merchant',
    meta: { title: '支付管理', icon: '' },
    children: [
      {
        path: '/merchant/index',
        name: 'merchant',
        component: () => import('@/views/merchant/index'),
        meta: { title: '商户号管理', icon: '' },
      },
      {
        path: '/merchant/servicePay',
        name: 'servicePay',
        component: () => import('@/views/merchant/servicePay.vue'),
        meta: { title: '客服消息支付', icon: '' },
      },
    ],
  },
  // 渠道管理
  {
    path: '/channel',
    component: Layout,
    redirect: '/channel/index',
    name: 'channel',
    meta: { title: '渠道管理', icon: '' },
    children: [
      {
        path: '/channel/index',
        name: 'channel',
        component: () => import('@/views/channel/index'),
        meta: { title: '渠道管理', icon: '' },
      },
      {
        path: '/channel/template',
        name: 'template',
        component: () => import('@/views/channel/component/rechargeTemplate'),
        meta: { title: '修改充值模版', icon: '' },
      },
    ],
  },
  {
    path: '/appContent',
    component: Layout,
    redirect: '/appContent/theater',
    name: 'appContent',
    meta: { title: '小程序内容管理', icon: '' },
    children: [
      {
        path: '/appContent/theater',
        name: 'theater',
        component: () => import('@/views/appContent/theater/index'),
        meta: { title: '剧场管理', icon: '' },
      },
      {
        path: '/appContent/wallpaper',
        name: 'wallpaper',
        component: () => import('@/views/appContent/wallpaper/index'),
        meta: { title: '壁纸管理', icon: '' },
      },
      {
        path: '/appContent/field',
        name: 'field',
        component: () => import('@/views/appContent/field/index'),
        meta: { title: '档位管理', icon: '' },
      },
      {
        path: '/appContent/introduce',
        name: 'introduce',
        component: () => import('@/views/appContent/introduce/index'),
        meta: { title: '介绍管理', icon: '' },
      },
      {
        path: '/appContent/analysis',
        name: 'analysis',
        component: () => import('@/views/appContent/analysis/index'),
        meta: { title: '剧集分析', icon: '' },
      },
    ],
  },
  // 订阅管理
  {
    path: '/appContent',
    component: Layout,
    redirect: '/subscribe/index',
    name: 'subscribe',
    meta: { title: '订阅推送', icon: '' },
    children: [
      {
        path: '/subscribe/index',
        name: 'index',
        component: () => import('@/views/subscribe/index'),
        meta: { title: '', icon: '' },
      },
    ],
  },
  // 合作方管理
  {
    path: '/appContent',
    component: Layout,
    redirect: '/cooperate/index',
    name: 'cooperate',
    meta: { title: '合作方管理', icon: '' },
    children: [
      {
        path: '/cooperate/index',
        name: 'index',
        component: () => import('@/views/cooperate/index'),
        meta: { title: '', icon: '' },
      },
    ],
  },
  // 渠道管理
  {
    path: '/payment',
    component: Layout,
    redirect: '/payment/index',
    name: 'payment',
    meta: { title: '付费管理', icon: '' },
    children: [
      {
        path: '/payment/index',
        name: 'payment',
        component: () => import('@/views/payment/index'),
        meta: { title: '付费管理', icon: '' },
      },
    ],
  },
  // 反馈
  {
    path: '/feedback',
    component: Layout,
    redirect: '/feedback/index',
    name: 'feedback',
    meta: { title: '投诉反馈', icon: '' },
    children: [
      {
        path: '/feedback/index',
        name: 'feedback',
        component: () => import('@/views/feedback/index'),
        meta: { title: '投诉反馈', icon: '' },
      },
    ],
  },
  // 合作方管理
  {
    path: '/distribution',
    component: Layout,
    redirect: '/distribution/index',
    name: 'distribution',
    meta: { title: '分销管理', icon: '' },
    children: [
      {
        path: '/distribution/index',
        name: 'index',
        component: () => import('@/views/distribution/index'),
        meta: { title: '', icon: '' },
      },
    ],
  },
  // 商户号管理
  {
    path: '/advertisement',
    component: Layout,
    redirect: '/advertisement/index',
    name: 'merchant',
    meta: { title: '广告流量主', icon: '' },
    children: [
      {
        path: '/advertisement/index',
        name: 'advertisement',
        component: () => import('@/views/advertisement/index'),
        meta: { title: '广告流量主', icon: '' },
      },
    ],
  },
  // 流量主收入
  {
    path: '/traffic',
    component: Layout,
    redirect: '/traffic/index',
    name: 'traffic',
    meta: { title: '流量主收入', icon: '' },
    children: [
      {
        path: '/traffic/index',
        name: 'traffic',
        component: () => import('@/views/traffic/index'),
        meta: { title: '流量主收入', icon: '' },
      },
    ],
  },
  {
    path: '/taskCenter',
    component: Layout,
    redirect: '/taskCenter/index',
    name: 'taskCenter',
    meta: { title: '运营管理', icon: '' },
    children: [
      {
        path: '/taskCenter/index',
        name: 'index',
        component: () => import('@/views/taskCenter/index'),
        meta: { title: '任务签到', icon: '' },
      },
      {
        path: '/taskCenter/miniappLink',
        name: 'miniappLink',
        component: () => import('@/views/taskCenter/miniappLink'),
        meta: { title: '小程序链接', icon: '' },
      },
      {
        path: '/taskCenter/activity',
        name: 'activity',
        component: () => import('@/views/taskCenter/activity'),
        meta: { title: '促销活动', icon: '' },
      },
      {
        path: '/taskCenter/coupons',
        name: 'coupons',
        component: () => import('@/views/taskCenter/coupons'),
        meta: { title: '卡券管理', icon: '' },
      },
      {
        path: '/taskCenter/purchase',
        name: 'purchase',
        component: () => import('@/views/taskCenter/purchase.vue'),
        meta: { title: '拼团管理', icon: '' },
      },
    ],
  },
  {
    path: '/drainageRule',
    component: Layout,
    redirect: '/drainageRule/index',
    name: 'drainageRule',
    meta: { title: '引流规则', icon: '' },
    children: [
      {
        path: '/drainageRule/index',
        name: 'index',
        component: () => import('@/views/drainageRule/index'),
        meta: { title: '引流规则', icon: '' },
      },
    ],
  },
  {
    path: '/recommends',
    component: Layout,
    redirect: '/recommends/index',
    name: 'recommends',
    meta: { title: '引流规则', icon: '' },
    children: [
      {
        path: '/recommends/index',
        name: 'index',
        component: () => import('@/views/recommends/index'),
        meta: { title: '引流规则', icon: '' },
      },
    ],
  },
  {
    path: '/playerIndex',
    component: Layout,
    redirect: '/player/index',
    name: 'playerIndex',
    meta: { title: '播放器管理', icon: '' },
    children: [
      {
        path: '/player/index',
        name: 'index',
        component: () => import('@/views/player/index'),
        meta: { title: '播放器管理', icon: '' },
      },
    ],
  },
  {
    path: '/knowledge',
    component: Layout,
    redirect: '/knowledge/index',
    name: 'knowledge',
    meta: { title: '知识库', icon: '' },
    children: [
      {
        path: '/knowledge/index',
        name: 'index',
        component: () => import('@/views/knowledge/index'),
        meta: { title: '知识库', icon: '' },
      },
    ],
  },
];

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/autoReply',
    component: Layout,
    // alwaysShow: true, // will always show the root menu
    redirect: '/autoReply/index',
    name: 'autoReply',
    meta: {
      title: '自动回复',
      icon: 'reply',
    },
    children: [
      {
        path: '/autoReply/index',
        component: () => import('@/views/autoReply/index'),
        name: 'autoReplyIndex',
        meta: { title: '自动回复', noCache: true },
      },
    ],
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
];
// console.log("------!!!!!!!!!!!!mode: import.meta.env.MODE === 'development' ? 'hash' : 'history'", 'mode:', import.meta.env.MODE === 'development' ? 'hash' : 'history')
const createRouter = () =>
  new Router({
    mode: import.meta.env.MODE === 'development' ? 'hash' : 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });
const router = createRouter();
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
